import {Bmob,initMasterBomb,initBmob} from "@/api/baseConfig/baseConfig";

var Goods = {
    //获取用户信息
    get: (params)=> {
        return new Promise((resolve, reject) => {
            let query=Bmob.Query("GoodsEntity");
            query.limit(params.pageSize);
            query.skip((params.nowPage-1)*params.pageSize);
            query.order("-createdAt");
            //模糊查询
            if(params.type && params.word){
                // query.equalTo(params.type,"==", { "$regex": "/" + params.word + "/i" });//模糊查询目前只提供给付费套餐会员使用
                query.equalTo(params.type, "==", params.word);
            }
            //分页查找
            query.find().then(res => {
                //模糊查询
                if(params.type && params.word){
                    // query.equalTo(params.type,"==", { "$regex": "/" + params.word + "/i" });//模糊查询目前只提供给付费套餐会员使用
                    query.equalTo(params.type, "==", params.word);
                }
                //统计总数
                query.count().then(count => {
                    console.log(count)
                    let newData={
                       results:res,
                       count
                    }
                    resolve(newData)
                })
            })
        })
    },

    set: (params)=>{
        return new Promise((resolve, reject) => {
            let GoodsEntity=Bmob.Query("GoodsEntity");
            GoodsEntity.set(params).then(res => {
                resolve(res)
            }).catch(err => {
                reject(err)
            });
        })
    },
}
export {
    Goods
}

